﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-04-18 11:17:07
 * 功能：基础数据
**************************************************************************************/

using Game.Framework;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace Game.BaseData
{
    public partial class Config
    {
        public float bgVolume;
        public Server server;
        public Ads ads;
        public Dot dot;
        public IAP iap;
        public Level level;
        /// <summary>道具基础数据</summary>
        public Props props;
        public Guide intro;
        public List<Country> counties;
        public Dictionary<string, string> lan;

        public void Parse(JObject source)
        {
            LogManager.Log($"call config.parse", "Config", "Parse");
            if (iap != null) iap.Parse();
            if (counties != null)
            {
                foreach (var item in counties)
                {
                    item.Parse();
                }
            }
        }

        /// <summary>根据布局ID得到布局信息</summary>
        public string GetLayoutById(int layoutId) => layoutId switch
        {
            1 => "4x5",
            2 => "5x6",
            3 => "6x6",
            4 => "6x7",
            5 => "6x8",
            6 => "6x9",
            _ => "4x4",
        };

        public class Ads
        {
            public string[] reward;
            public string[] interstitial;
            public string[] open;
            public string[] banner;
            public int add;             //第x关增加激励后的插屏
            public int inter;           //第x关结束后增加定时插屏
            public int open_c;          //第x关结束后增加冷启动开屏（首次启动）
            public int open_h;          //第x关结束后增加热启动开屏（从后台切回来）
        }

        public class Dot
        {
            public float mmp_ra;
        }

        public class Props
        {
            public Prop hint;
            public Prop shuffle;
            public Prop bomb;
            public Prop time;
            public Prop error;
            public Prop timeLimit;
        }

        public class Prop
        {
            public int cost;
            public int unlock;
            public int seconds; // 添加时间数，单位：秒（仅用于time道具）
        }

        public class Server
        {
            public string url;
            public Tag[] tags;

            public class Tag
            {
                public string key;
                public string sign;
            }
        }

        // 关卡配置
        public class Level
        {
            public int int_coins;               // 初始金币数
            public int s_level;                 // 每x关出现一个隐藏关卡
            public int maxLv;                   // 最大关卡等级
            public Base[] level_data;           // 基础等级数据
            public Base other_level;            // 大于基础等级的随机数据
            public int revivalCost;             // 复活需要的金币数
            public int revivalAddSeconds;       // 闯关失败复活增加的时间，单位：秒

            public class Base
            {
                public int lv;
                public int[] map;               // 布局编号
                public int time;                // 倒计时的时间
                public int type;                // 关卡中出现的卡片ID数量
                public int[] tag;               // 4张图分别选用的是tags数组中的第几个，从0开始
                public int download_cost;       // 下载所需金币
                public int download_ads;        // 下载所需广告次数
                public int[] rewards;           // 奖励金币
            }
        }

        public class Guide
        {
            public Module starter;
            public Module props;
            public Module functions;

            public class Module
            {
                public int status;
                public string[] content;
            }
        }

        // 地图基础数据
        public class Country
        {
            public string name;
            public bool isUnlock;
            public List<City> cities;
            public Dictionary<string, City> citiesDict;

            public void Parse()
            {
                if (cities != null)
                {
                    citiesDict = new Dictionary<string, City>(cities.Count);
                    foreach (var item in cities)
                        citiesDict.Add(item.name, item);
                }
            }

            public City this[string name]
            {
                get
                {
                    if (citiesDict == null) return null;
                    citiesDict.TryGetValue(name, out var result);
                    return result;
                }
            }
        }

        public class City
        {
            public string name;
            public int needStar;
            public int adCount;
            public int coins;
            public int[] tag;
            public string desc;
            public float posX;
            public float posY;
        }
    }
}